﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Chronos;

public class AutoMove : SkillBase
{
    public float speedRatio = 1;
    public Vector2 aim;
    public Transform target;
    public RigidbodyTimeline2D rb;
    public float keepDistance = 1;
    public override void Init(EntityBase user)
    {
        User = user;
        rb = User.time.rigidbody2D;
        
    }
    public override void FixedUpdate()
    {
        aim = User.parameter.AimData.aimDir;
        target = User.parameter.AimData.target;
        if (target != null)
        {
            if(User.parameter.AimData.distance > keepDistance)
            {
                rb.velocity = aim
                         * User.parameter.MovementData.moveSpeed
                         * speedRatio;
                User.parameter.MovementData.moveDir = aim;
                User.ChangeState(States.MoveState);
            }else
            {
                User.ChangeState(States.StandState);
                rb.velocity = Vector2.zero;
            }
            
        }else if(target == null)
        {
            User.ChangeState(States.StandState);
            rb.velocity = Vector2.zero;
        }

    }
}
